import { post } from '@/http/axios'
import { handleData, normalTree } from '@/util/data'

// ---------------------------------字段库---------------------------------
// field_view_type	控件类型
// field_code	字段编码
// field_name	字段显示名称/key
// field_section_type	所属模块
// field_right	写入只读权限
// is_required	是否必填 1是 2否
// field_remark	备注
// exList
export const addFieldData = (...args) => post('/addWorkColumn', ...args)

// pageNumber	当前页码
// pageSize	每页展示行数
// token	token
// keywordSearch	关键字
// work_template_code	工单模板主键,工单模板添加字段弹框查询附带
export const getFieldData = (...args) => post('/searchWorkColumnList', ...args)

// field_form_code	字段主键
export const getFieldInfo = (...args) => post('/searchWorkColumnInfo', ...args)

// field_form_code	字段主键

// field_view_type	控件类型
// field_code	字段编码
// field_name	字段显示名称/key
// field_section_type	所属模块
// field_right	写入只读权限
// is_required	是否必填 1是 2否
// field_remark	备注
// exList
export const editFieldData = (...args) => post('/editWorkColumn', ...args)

// field_form_code
export const delFieldData = (...args) =>
  post('/removeSelectWorkColumn', ...args)
// ---------------------------------工单模板---------------------------------

const config = [
  [
    'work_template_name',
    'work_template_code',
    'work_template_code',
    'work_template_name'
  ],
  ['label', 'value', 'work_template_code', 'work_template_name']
]
// keywordSearch	关键字
export const getTemplateData = async (...args) => {
  const { code, data, cancelMessage } = await post(
    '/searchWorkTemplateList',
    ...args
  )
  if (data)
    return {
      code,
      data: handleData(data, config, { all: true }),
      cancelMessage
    }
  return { code, cancelMessage }
}

// work_template_name	模板名称
// remark	备注
export const addTemplateData = (...args) => post('/addWorkTemplate', ...args)

// work_template_code	选中数据主键
export const delTemplateData = (...args) =>
  post('/removeSelectWorkTemplate', ...args)

// work_template_code
// work_template_name	模板名称
// remark	备注
export const editTemplateData = (...args) => post('/editWorkTemplate', ...args)

// work_template_code
export const getTemplateInfo = (...args) =>
  post('/searchWorkTemplateInfo', ...args)

// ------------------------------模版字段-----------------------------

// keywordSearch	关键字
// work_template_code	模板主键
export const getTemplateFiledData = (...args) =>
  post('/searchWorkTemplateColumnList', ...args)

// keywordSearch	关键字
// work_template_code	工单模板主键,工单模板添加字段弹框查询附带
export const getTemplateFiledSelect = (...args) =>
  post('/searchWorkColumnListForTemplate', ...args)

// field_form_codes	选中字段主键字符串
// work_template_code	模板主键
export const addTemplateFiledData = (...args) =>
  post('/addWorkTemplateColumn', ...args)
// work_template_code	模板主键
// field_form_code	字段主键
export const delTemplateFiledData = (...args) =>
  post('/removeSelectWorkTemplateColumn', ...args)

// id	数据主键
// work_template_code	模板主键
// field_form_code	字段主键

// field_view_type	控件类型
// field_code	字段编码
// field_name	字段显示名称/key
// field_section_type	所属模块
// field_right	写入只读权限
// is_required	是否必填 1是 2否
// field_remark	备注
// exList
// linkList
export const editTemplateFiledData = (...args) =>
  post('/editWorkTemplateColumn', ...args)

// work_template_code	模板主键
// field_form_code	字段主键
export const getTemplateFieldInfo = (...args) =>
  post('/searchWorkTemplateColumnInfo', ...args)

// ---------------------------------流程配置---------------------------------

const pConfig = [
  [
    'pageId',
    'parentPageId',
    'pageId',
    'name',
    'id',
    'is_node',
    'id',
    'parent',
    'node_type',
    'flow_code',
    'name',
    'name'
  ],
  [
    'id',
    'pid',
    'nid',
    'label',
    'value',
    'isNode',
    'node_id',
    'pref_id',
    'type',
    'flow_code',
    'flow_name',
    'node_name'
  ]
]
export const getProcessData = async (...args) => {
  const { code, data, cancelMessage } = await post(
    '/searchWorkflowInstDspList',
    ...args
  )
  if (data)
    return {
      code,
      data: normalTree(handleData(data, pConfig)),
      cancelMessage
    }
  return { code, cancelMessage }
}

// node_id id
// node_type flow:1,node:2,subNode:3
// pref_id
// keywordSearch	关键字
export const getProcessFieldData = (...args) =>
  post('/searchWorkFlowTemplateColumnList', ...args)

// id
export const getProcessFieldInfo = (...args) =>
  post('/searchWorkFlowColumnInfo ', ...args)
// node_id id
// node_type flow:1,node:2,subNode:3
// pref_id
// field_form_codes	选中字段主键字符串
export const addProcessFieldData = (...args) =>
  post('/addWorkFlowTemplateColumn', ...args)

// id	数据主键
// field_form_code	字段主键

// field_view_type	控件类型
// field_code	字段编码
// field_name	字段显示名称/key
// field_section_type	所属模块
// field_right	写入只读权限
// is_required	是否必填 1是 2否
// field_remark	备注
// exList
// linkList
export const editProcessFieldData = (...args) =>
  post('/editWorkFlowTemplateColumn', ...args)

// id
export const delProcessFieldData = (...args) =>
  post('/removeSelectWorkFlowColumn', ...args)

// keywordSearch	关键字
// node_id id
// node_type flow:1,node:2,subNode:3
// pref_id
export const getProcessFieldSelect = (...args) =>
  post('/searchWorkFlowColumnListForAdd', ...args)

// node_id id
// node_type flow:1,node:2,subNode:3
// pref_id pid 同 id
// flow_code	流程code
// flow_name	流程名称
// relation_type 适用对象
// work_type_id 工单类型
// work_template_code 模版id
export const editProcessNodeData = (...args) =>
  post('/editWorkFlowTemplate', ...args)

// node_id id
// node_type flow:1,node:2,subNode:3
// pref_id pid 同 id
export const getProcessNodeData = (...args) =>
  post('/searchWorkFlowTemplateInfo', ...args)

// node_id -id
// node_type flow:1,node:2,subNode:3
// pref_id pid
// node_name
// show_name
export const editProcessLeafData = (...args) =>
  post('/editWorkFlowTemplate', ...args)

// node_id -id
// node_type flow:1,node:2,subNode:3
// pref_id pid
export const getProcessLeafData = (...args) =>
  post('/searchWorkFlowTemplateInfo', ...args)

// field_right	写入只读权限 readonly 只读 ； edit 写入
// field_section_type	所属模块
// field_is_show	是否显示： show 显示， hide 隐藏
// id	数据库主键
// type	类型 1、所属区块 2、是否显示 3、只读、写入权限 4、上移 5、下移
export const changeProcessFieldMod = (...args) =>
  post('/editWorkFlowColumnUse', ...args)
